package cn.daniellee.plugin.ib.menu;

import cn.daniellee.plugin.ib.InfiniteBlock;
import cn.daniellee.plugin.ib.component.ItemGenerator;
import cn.daniellee.plugin.ib.core.BlockCore;
import cn.daniellee.plugin.ib.model.PlayerData;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.bukkit.Bukkit;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class AdminMenu {

	public static Inventory generate(int page) {
		List<PlayerData> playerData = BlockCore.getUnreviewedBuildings();
		int size = playerData.size() > 45 ? 54 : 45;
		Inventory menu = Bukkit.createInventory(new ReviewMenuHolder(), size, InfiniteBlock.getInstance().getConfig().getString("menu.review.title", "&6&lReview building").replace("&", "§"));

		List<String> lore = InfiniteBlock.getInstance().getConfig().getStringList("menu.review.button.lore");
		List<String> operationLore = InfiniteBlock.getInstance().getConfig().getStringList("menu.review.button.operation-lore");
		SimpleDateFormat format = new SimpleDateFormat(InfiniteBlock.getInstance().getConfig().getString("menu.common.date-format", "yyyy-MM-dd"));
		for (int i = 0; i < 45; i++) {
			int targetIndex = i + 45 * (page - 1);
			if (targetIndex >= playerData.size()) break;


		}


		if (size == 54) {
			// 上一页按钮
			if (page > 1) {
				menu.setItem(45, ItemGenerator.getItem(InfiniteBlock.getInstance().getConfig().getString("menu.common.back.name", "&eBack to {page}").replace("{page}", "[" + (page - 1) + "]"), null, InfiniteBlock.getInstance().getConfig().getString("menu.common.back.item.material", "RED_WOOL"), InfiniteBlock.getInstance().getConfig().getInt("menu.common.back.item.durability", 0)));
			}
			// 下一页按钮
			if (45 * page < playerData.size()) {
				menu.setItem(53, ItemGenerator.getItem(InfiniteBlock.getInstance().getConfig().getString("menu.common.next.name", "&eNext to {page}").replace("{page}", "[" + (page + 1) + "]"), null, InfiniteBlock.getInstance().getConfig().getString("menu.common.next.item.material", "LIME_WOOL"), InfiniteBlock.getInstance().getConfig().getInt("menu.common.next.item.durability", 0)));
			}
		}
		return menu;
	}

	public static class ReviewMenuHolder implements InventoryHolder {
		@Override
		public Inventory getInventory() {
			return Bukkit.createInventory(null, 54);
		}
	}
}
